<?php
/**
 * 友情链接
 */
namespace Admin\Controller;
class BlogrollController extends AdminBaseController {
	/**
	 * 链接列表
	 */
	public function index(){
		$blogrollModel = new \Common\Model\BlogrollModel();
        $this->assign('data',$blogrollModel->getListData(5));
        $this->display();	
	}
	/**
     * 添加链接 | 编辑链接
     */
    public function add_blogroll(){
        $id = I('get.id',0,'intval');
        $blogrollModel = new \Common\Model\BlogrollModel();
        if (IS_AJAX) {
            if (!$blogrollModel->send_addData()) {
                exit(json_encode(array('status'=>0,'msg'=>$blogrollModel->getError())));
            } else {
                exit(json_encode(array('status'=>1,'msg'=>'操作成功.^_^','url'=>U('Blogroll/index'))));
            }
        }
        if ($id) {
            //编辑
            $this->assign('data',$blogrollModel->getFindData($id));
            $this->display('edit_blogroll');
        } else {
            $this->display('add_blogroll');
        }
    }
	/**
	 * 删除链接
	 *
	 */
	public function del_blogroll(){
		if (IS_AJAX) {
            $blogrollModel = new \Common\Model\BlogrollModel();
            $id = I('post.id',0,'intval');
            if ($id) {
                if ($blogrollModel->execDelData($id)) {
                    exit(json_encode(array('status'=>1,'msg'=>'操作成功')));
                } else {
                    exit(json_encode(array('status'=>0,'msg'=>'操作失败')));
                }
            } else {
                exit(json_encode(array('status'=>0,'msg'=>'请求失败,请重试...')));
            }
        }
    }
}